/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.swing.jxTable;

/**
 *
 * @author vinicius
 */
import core.connector.DownloadableItem;
import java.util.Comparator;
import javax.swing.JLabel;
import org.jdesktop.swingx.renderer.CheckBoxProvider;
import org.jdesktop.swingx.renderer.LabelProvider;
import org.jdesktop.swingx.renderer.StringValue;
import resources.Messages;


public class DownloadableRendering {
        
    
    public static void configureColumnFactory(CustomColumnFactory factory) {
        Comparator<DownloadableItem> comparator = new Comparator<DownloadableItem>() {
            @Override
            public int compare(DownloadableItem o1, DownloadableItem o2) {
                String fn1 = o1.getFileName();
                String fn2 = o2.getFileName();
                if (fn1 == null) return -1;
                if (fn2 == null) return 1;
                return fn1.compareTo(fn2);
            }
            
        };
        factory.addComparator("geral.file", comparator);        
        
        factory.addComponentProvider("check", new CheckBoxProvider(null,JLabel.CENTER));
        factory.addComponentProvider("geral.file", new LabelProvider(JLabel.LEFT));
        factory.addComponentProvider("geral.size", new LabelProvider(new StringValue() {
            @Override
            public String getString(Object o) {
                Long size = (Long)o;
                if(size == DownloadableItem.UNKNOW_SIZE){
                    return Messages.message.getString("geral.unknown");
                }
                return o.toString();
            }
        },JLabel.LEFT));        
    }
    
}